package com.baibei.ebec.user.systemmessage;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baibei.ebec.user.R;
import com.baibei.ebec.user.R2;
import com.baibei.model.BuyDirection;
import com.baibei.model.MessageInfo;
import com.baibei.model.MsgInfo;
import com.baibei.model.OrderInfo;
import com.baibei.model.SysMsgInfo;
import com.baibei.module.OnItemSelectListener;
import com.baibei.order.bill.sticky_header.StickyDateAdapter;
import com.baibei.order.bill.viewholder.DateViewHolder;
import com.baibei.order.bill.viewtype.ViewType;
import com.baibei.widget.PriceTextView;
import com.blankj.utilcode.utils.TimeUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by shenminjie on 2017/8/9.
 * mail:shenminjie@100bei.com
 */

class MessageAdapter extends StickyDateAdapter<SysMsgInfo> {

    /**
     * 回调操作
     */
    private OnItemSelectListener<SysMsgInfo> mListener;

    /**
     * 设置监听
     *
     * @param listener listener
     */
    void setOnListener(OnItemSelectListener<SysMsgInfo> listener) {
        mListener = listener;
    }

    @Override
    public RecyclerView.ViewHolder getItemViewHolder(ViewGroup parent, int viewType) {
        if (viewType == ViewType.ITEM.ordinal()) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message, parent, false);
            return new MessageAdapter.ItemViewHolder(view);
        }
        return null;
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof ItemViewHolder) {
            ItemViewHolder viewHolder = (ItemViewHolder) holder;
            final SysMsgInfo info = mRecordObjs.get(position);
            viewHolder.tv_Date.setText(info.getDtime());
            viewHolder.tv_contnet.setText(info.getMessage());
            viewHolder.tvType.setText(info.getTitle());
            int res_id;
            switch (info.getState()){
                case "state1":
                    viewHolder.iv_img.setImageResource(R.drawable.message_price);
//                    viewHolder.tvType.setText("价格提醒");
                    break;
                case "state2":
                    viewHolder.iv_img.setImageResource(R.drawable.message_orderback);
//                    viewHolder.tvType.setText("自动退订");
                    break;
                case "state3":
                    viewHolder.iv_img.setImageResource(R.drawable.message_quan);
//                    viewHolder.tvType.setText("体验券到账");
                    break;
            }

        }

    }


    static class ItemViewHolder extends RecyclerView.ViewHolder {
        @BindView(R2.id.tv_contnet)
        TextView tv_contnet;
        @BindView(R2.id.iv_img)
        ImageView iv_img;
        @BindView(R2.id.tv_date)
        TextView tv_Date;
        @BindView(R2.id.tv_type)
        TextView tvType;

        ItemViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
